package com.pausa.sgdi.controls
{
	import com.pausa.sgdi.ejb.entities.Direccion;
	import com.pausa.sgdi.ejb.entities.Empresa;
	import com.pausa.sgdi.view.DomicilioPopUpView;
	import com.pausa.sgdi.view.menu.event.GenericEvent;
	
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.ui.Mouse;
	
	import mx.containers.FormItem;
	import mx.containers.HBox;
	import mx.containers.TitleWindow;
	import mx.controls.Button;
	import mx.controls.TextInput;
	import mx.core.Application;
	import mx.managers.ISystemManager;
	import mx.managers.PopUpManager;
	
	public class DomicilioPopUpFormItem extends FormItem
	{
		private var btnSelect : Button;
		private var txtInput : TextInput;
		private var popUp : TitleWindow;
		
		public var direccion:Direccion;
		
		public function DomicilioPopUpFormItem()
		{
			super();
			var container : HBox = new HBox();
			txtInput = new TextInput();
			btnSelect =  new Button();
			btnSelect.addEventListener(MouseEvent.CLICK, onMouseClikHandler);
			container.addChild(txtInput);
			container.addChild(btnSelect);
			addChild(container);
		}
		
		private function onMouseClikHandler(event : MouseEvent):void
		{
			popUp=  new DomicilioPopUpView();
			popUp.addEventListener(GenericEvent.GUARDAR_DIRECCION, onguardarDireccion);
			var parent:Sprite
			var sm:ISystemManager = ISystemManager(Application.application.systemManager);
			if (sm.useSWFBridge())
				parent = Sprite(sm.getSandboxRoot());
			else
				parent = Sprite(Application.application);
			
			PopUpManager.addPopUp(popUp,parent,true);
			PopUpManager.centerPopUp(popUp);
		}
		
		
		private function onguardarDireccion(event : GenericEvent):void
		{
			popUp.removeEventListener(GenericEvent.GUARDAR_DIRECCION, onguardarDireccion);
			popUp = null;
			
			direccion= Direccion(event.selectedItem);
			
		}
		
		
		
		
		
	}
}